       IDENTIFICATION DIVISION.
       PROGRAM-ID.   GUARNA-TP1.
       AUTHOR.       PINEDA-ARMANDO-FACUNDO.

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SPECIAL-NAMES.
           DECIMAL-POINT IS COMMA.
SEC-IO INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT FILE-CLI ASSIGN TO DISK
                     ORGANIZATION IS LINE SEQUENTIAL
                     FILE STATUS IS WSS-FS-FILE-CLI.
           SELECT FILE-IDX-CLI ASSIGN TO DISK
           ACCESS MODE IS SEQUENTIAL
           RECORD KEY IS IDX-KEY
           ALTERNATE RECORD KEY IS IDX-DOCUMENTO WITH 
		   DUPLICATES
           ORGANIZATION IS INDEXED
           FILE STATUS IS WSS-FS-FILE-IDX-CLI.
           
SEC-DD DATA DIVISION.
       FILE SECTION.
      *****************************************
      * DECLARACION DE NOMBRES DE ARCHIVOS Y SUS REGISTROS
      *****************************************
       FD FILE-CLI LABEL RECORD IS STANDARD
             VALUE OF FILE-ID IS "clientes.dat".
       01 REG-FILE-CLI.
          03 CLI-NUMERO                PIC X(8).
          03 CLI-FEC-ALTA                  PIC 9(8).
          03 CLI-TELEFONO               PIC X(20).
          03 CLI-DIRECCION                PIC X(30).
          03 CLI-DOCUMENTO               PIC X(20).
          
       FD FILE-IDX-CLI LABEL RECORD IS STANDARD
             VALUE OF FILE-ID IS "clientes.idx".
       01 REG-FILE-IDX-CLI.
          03 IDX-KEY.                        
           05 IDX-NUMERO                PIC X(8).
          03 IDX-FEC-ALTA                  PIC 9(8).
          03 IDX-TELEFONO               PIC X(20).
          03 IDX-DIRECCION                PIC X(30).
          03 IDX-DOCUMENTO               PIC X(20).

.     *----------------------------------------------------------------*
SEC-WS WORKING-STORAGE SECTION.
      *----------------------------------------------------------------*
     
      *----------------------------------------------------------------*
.     * VARIABLES GENERALES
      *----------------------------------------------------------------*
.     *----------------------------------------------------------------*
      * CONSTANTES
      *----------------------------------------------------------------*
       01 WSC-OK                       PIC X(2) VALUE '00'.
       01 WSC-EOF                      PIC X(2) VALUE '10'.
.     *----------------------------------------------------------------*
      * FILE STATUS
      *----------------------------------------------------------------*
       01 WSS-FS-FILE-CLI               PIC X(02).
          88 WSS-88-OK-FILE-CLI         VALUE ZEROES.
          88 WSS-88-EOF-FILE-CLI        VALUE '10'.
       01 WSS-FS-FILE-IDX-CLI           PIC X(02).
          88 WSS-88-OK-FILE-IDX-CLI     VALUE ZEROES.
          88 WSS-88-EOF-FILE-IDX-CLI    VALUE '10'.

      *************************************************
      * PROCEDURE DIVISION - AREA DE PROGRAMA 1ER NIVEL
      *************************************************
DIV-PR PROCEDURE DIVISION.
       COMIENZO.
           PERFORM 1000-INICIO 
              THRU 1000-INICIO-EXIT.
              
           PERFORM 2000-COPIA
              THRU 2000-COPIA-EXIT
              UNTIL WSS-FS-FILE-CLI = '10'
               
           PERFORM 9000-FIN
              THRU 9000-FIN-EXIT.
      ***************************************************************
.     *APERTURA DE LOS ARCHIVOS
      ***************************************************************
       1000-INICIO.
           DISPLAY "INICIO".
           OPEN INPUT FILE-CLI.
           OPEN OUTPUT FILE-IDX-CLI.
       1000-INICIO-EXIT.
      ***************************************************************
.     *COPIA AL INDEXADO
      ***************************************************************
       2000-COPIA.
           DISPLAY "COPIA".
           PERFORM LECTURA THRU LECTURA-EXIT    
           MOVE REG-FILE-CLI TO REG-FILE-IDX-CLI.
           IF WSS-FS-FILE-CLI = '00' THEN
               DISPLAY 'KEY: ' IDX-KEY           
               WRITE REG-FILE-IDX-CLI
           END-IF.
           DISPLAY "NO COPIA".
       2000-COPIA-EXIT.
       
       
.     *LECTURA
       LECTURA.
           READ FILE-CLI AT END CONTINUE.
           EVALUATE TRUE
               WHEN WSS-88-OK-FILE-CLI 
                    DISPLAY 'UN CLI LEIDO'
               WHEN WSS-88-EOF-FILE-CLI
                    CONTINUE
               WHEN OTHER
                    DISPLAY 'ERROR ' WSS-FS-FILE-CLI
                    STOP RUN
           END-EVALUATE.
       LECTURA-EXIT.
           EXIT.
      ***************************************************************
.     *CIERRE DE TODOS LOS ARCHIVOS
      ***************************************************************
       9000-FIN.
           CLOSE FILE-CLI.
           CLOSE FILE-IDX-CLI.
           DISPLAY "FIN DE PROGRAMA GUARNA-TP1".
           STOP RUN.
       9000-FIN-EXIT.
           EXIT.